<template>
  <view class="good-list">
    这个是商品列表页面
    <view class="goods-list-box" v-for="(item,index) in goodList" :key="index" @click="gotoDatail(item)">

     <my-goods :goods="item"></my-goods>
     
    </view>
  </view>
</template>

<script>
  export default {
    data() {
      return {
        queryObj:{
          query:'',
          cid:'',
          pagenum:1,
          pagesiza:10
        },
        goodList:[],
        total:0,
        isLoading:false
      };
    },
    methods:{
      async getGoodList(cd){
        this.isLoading = true
        let { data:result } = await uni.$http.get('/api/public/v1/goods/search',this.queryObj);
        this.isLoading = false
        //判断有没有传参
        cd&&cd()
      if(result.meta.status != 200){
        uni.$showMsg();
        return;
      }
        this.goodList = [...this.goodList, ...result.message.goods]
        this.total = result.message.total
      },
      
      gotoDatail(item){
        console.log(123);
        console.log(item);
        uni.navigateTo({
          url:'/subPackage/goods_detail/goods_detail?goods_id=' + item.goods_id
        })
      }
    }
    ,
    onLoad(options){
      this.queryObj.cid = options.cid || '',
      this.queryObj.query = options.query || '',
      this.getGoodList();
    },
    onReachBottom(){
      if(this.queryObj.pagenum * this.queryObj.pagesiza >= this.total )  return   uni.$showMsg('已经到地')
      if(this.isLoading) return
      this.queryObj.pagenum += 1;
      this.getGoodList()
    },
    onPullDownRefresh(){
      this.queryObj.pagenum = 1;
      this.total = 0,
      this.isLoading = false,
      this.goodList = [],
      this.getGoodList(()=>uni.stopPullDownRefresh())
    }
  }
</script>

<style lang="scss">

</style>
